<template>
    <div style="margin: 0px auto">

        <span style="font-size: 20px;font-weight: bold;margin:0px auto;">售后审核</span>
        <div>
            <el-form :model=" storeid" :rules="rules" ref="storeid" label-width="100px" class="demo-ruleForm"
                     style="margin-left: 250px">
                <el-form-item label="分店筛选:">
                    <el-select v-model="storeid.id" placeholder="请选择" style="width: 300px" @change="getlogin()">
                        <el-option
                                v-for="item in storeid"
                                :key="item.value"
                                :label="item.name"
                                :value="item.id">
                        </el-option>
                    </el-select>
                    &nbsp;
                    <el-button icon="el-icon-search" @click="selctClick()" circle></el-button>
                    <!--<el-button type="primary" @click="selctClick()">查询</el-button>-->
                </el-form-item>
            </el-form>
        </div>
        <template>
            <el-table
                    :data="tableData"
                    border
                    style="width: 100%">
                <el-table-column
                        fixed
                        prop="id"
                        label="ID"
                        width="150">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="storename"
                        label="分店名称"
                        width="150">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="nickname"
                        label="用户昵称"
                        width="150">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="managername"
                        label="管理员名称"
                        width="150">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="productname"
                        label="商品名称"
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="because"
                        label="原因"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="state"
                        label="状态"
                        width="120">
                </el-table-column>
                <el-table-column
                        fixed="right"
                        label="操作"
                        width="100">
                    <template slot-scope="scope">
                        <!--具体操作-->
                        <el-button @click="handleClick(scope.row)" type="text" size="small">退款</el-button>
                        <el-button @click="NOhandleClick(scope.row)" type="text" size="small">不退款</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block" style="margin-left: 250px">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page.sync="currentPage3"
                        :page-size="100"
                        layout="prev, pager, next, jumper"
                        :total="1000">
                </el-pagination>
            </div>
        </template>
    </div>
</template>

<script>
    export default {
        name: "salemanage",
        data() {
            return {
                //测试用的数据，可以删除
                tableData: [{
                    //ID
                    id: '',
                    //原因
                    because: '',
                    //状态
                    state: '',
                    //分店名
                    storename: '',
                    //管理员
                    managername: '',
                    //原因
                    becaus: '',
                    //商品名称
                    productname: '',
                    //用户昵称
                    nicknme: '',
                }],
                storeid: [{
                    id: '',
                    name: '',
                    region: ''
                }],
                options: [{
                    value: '0',
                    label: '未处理'
                }, {
                    value: '1',
                    label: '已退款',
                }, {
                    value: '2',
                    label: '未退款'
                }],
                value: ''
            }
        },
        methods: {
            //根据分店筛选
            getlogin() {
                var obj = this.storeid.find((item) => {
                    return item.id == this.storeid.id;
                });
                this.axios.get("/Salea/QueryAllSalea", {
                    params: {
                        storeid: obj.id
                    }
                }).then(response => {
                    if (response.data == null) {
                        this.$message.error("请求数据为空！")
                    } else {
                        this.tableData = response.data;
                    }
                })
            },
            //点击退款修改状态
            handleClick(row) {
                var sta = row.state;
                var id = row.id;
                var obj = this.storeid.find((item) => {
                    return item.id == this.storeid.id;
                });
                if (obj == null) {
                    this.$alert("请先选择分店");
                }
                if (sta == 0) {
                    sta = 1;
                } else {
                    this.$alert("请先选择分店");
                }
                this.axios.get("/Salea/UpdSaleaState", {
                    params: {
                        id: id,
                        storeid: obj.id,
                        state: sta
                    }
                }).then(response => {
                    if (response.data == null) {
                        this.$message.error("请求数据为空")
                    } else {
                        this.axios.post("/Salea/selectAll").then(response => {
                            this.tableData = response.data;
                        }).catch((error) => {
                            this.$alert(error)
                        });
                    }
                })
            },
            //点击不退款修改状态
            NOhandleClick(row) {
                var sta = row.state;
                var id = row.id;
                var obj = this.storeid.find((item) => {
                    return item.id == this.storeid.id;
                });
                if (obj == null) {
                    this.$alert("请先选择分店");
                }
                if (sta == 0) {
                    sta = 2;
                } else {
                    this.$alert("错误！")
                }
                this.axios.get("/Salea/UpdSaleaState", {
                    params: {
                        id: id,
                        storeid: obj.id,
                        state: sta
                    }
                }).then(response => {
                    if (response.data == null) {
                        this.$alert("失败");
                    } else {
                        this.$alert("成功");
                        this.axios.post("/Salea/selectAll").then(response => {
                            this.tableData = response.data;
                        }).catch((error) => {
                            this.$alert(error);
                        });
                    }
                })
            },
            //根据状态查询
            stateClick() {
                var obj = this.storeid.find((item) => {
                    return item.id == this.storeid.id;
                });
                var opn = this.options.find((item) => {
                    return item.id == this.options.value;
                });
                this.axios.get("/Salea/QuerySaleaWhere", {
                    params: {
                        storeid: obj.id,
                        state: opn.value
                    }
                }).then(response => {
                    if (response == null) {
                        this.$alert("失败");
                    } else {
                        this.tableData = response.data;
                    }
                })
            },
            //点击查询所有
            selctClick() {
                this.storeid = this.storeid[0].id;
                this.axios.post("/Salea/selectAll").then(response => {
                    this.tableData = response.data;
                }).catch((error) => {
                    this.$alert(error);
                });
                //查询分店ID
                this.axios.post("/Stores/QueryAllStores").then(response => {
                    if (response.data == null) {
                        this.$alert("失败");
                    } else {
                        this.storeid = response.data;
                    }
                });
                // location.reload();刷新当前页面
            }
        },
        created() {
            //默认加载
            this.axios.post("/Salea/selectAll").then(response => {
                this.tableData = response.data;
                // for (var i = 0; i < this.tableData.length; i++) {
                //     if (this.tableData[i].state == 0) {
                //         this.tableData[i].state = '未处理';
                //     } else if (this.tableData[i].state == 1) {
                //         this.tableData[i].state = '退款';
                //     } else {
                //         this.tableData[i].state = '不退款';
                //     }
                // }
            }).catch((error) => {
                this.$alert(error);
            });
            //查询分店ID
            this.axios.post("/Stores/QueryAllStores").then(response => {
                if (response.data == null) {
                    this.$alert("失败");
                } else {
                    this.storeid = response.data;
                }
            });
        }
    }
</script>

<style scoped>

</style>